@echo off
title Ruoyi-ai Application Restart Script

set APP_HOME=%~dp0

echo Restarting Ruoyi-ai Application...

REM 停止应用
if exist "%APP_HOME%stop.bat" (
  call "%APP_HOME%stop.bat"
) else (
  echo Stop script not found. Trying to stop via PID file...
  set PID_FILE=%APP_HOME%app.pid
  if exist "%PID_FILE%" (
    set /p PID=<"%PID_FILE%"
    taskkill /PID %PID% /T /F >nul 2>&1
    if %errorlevel% equ 0 (
      del /f /q "%PID_FILE%" >nul 2>&1
      echo Application stopped.
    )
  )
)

REM 等待几秒确保应用完全停止
timeout /t 3 /nobreak >nul

REM 启动应用
if exist "%APP_HOME%start.bat" (
  call "%APP_HOME%start.bat"
) else (
  echo Start script not found.
  pause
  exit /b 1
)

echo Ruoyi-ai Application restarted successfully.
pause